package com.life.ai.server.modules.develop.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.life.ai.server.common.domain.PageQuery;
import com.life.ai.server.framework.syslog.event.SysLogEvent;
import com.life.ai.server.modules.develop.entity.SysLog;
import com.life.ai.server.modules.develop.mapper.SysLogMapper;
import com.life.ai.server.modules.develop.service.SysLogService;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 日志表 服务实现类
 * </p>
 *
 * @author kyle
 * @since 2024-06-14
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    /**
     * 操作日志记录
     *
     * @param sysLogEvent 操作日志事件
     */
    @Async
    @EventListener
    public void recordSysLog(SysLogEvent sysLogEvent) {
        SysLog sysLog = BeanUtil.toBean(sysLogEvent, SysLog.class);
        this.save(sysLog);
    }

    /**
     * 分页查询
     *
     * @param pageQuery 分页参数
     * @param sysLog 查询条件
     * @return Page<SysLog>
     */
    @Override
    public Page<SysLog> queryPage(PageQuery pageQuery,SysLog sysLog){
        return lambdaQuery().page(pageQuery.build());
    }
}

